package com.heima.feigins.fallback;

import com.heima.feigins.ArticleFeigin;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/*
* 服务降级，相当于兜底策略一样，feign接口中方法出错，会调用这里的方法
* */
@Component("articleFeigin") //加入到IOC容器
@Slf4j   //日志注解
public class ArticleFeiginFallback implements FallbackFactory<ArticleFeigin> {


    @Override
    public ArticleFeigin create(Throwable throwable) {
        return new ArticleFeigin() {
            @Override
            public ResponseResult<ApAuthor> findByUserId(Integer userId) {
                log.error("根据用户id查询用户，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<ApAuthor> save(ApAuthor apAuthor) {
                log.error("根据文章作者信息，服务远程调用出错");
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }
        };
    }
}

